package com.bolingcavalry.rabbitmq;

import com.alibaba.fastjson.JSONObject;
import com.bolingcavalry.MainApplication;
import com.bolingcavalry.rabbitmq.model.SendModel;
import com.winit.cloudlink.Cloudlink;
import com.winit.cloudlink.event.Event;
import com.winit.cloudlink.event.EventOperation;
import com.winit.cloudlink.message.Message;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.*;

/**
 * Created by wanglin on 2018/5/15.
 */
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = MainApplication.class)
public class Send {
    @Resource
    private Cloudlink cloudlink;

    @Value("${cloudlink.appId}")
    private String appId;
    @Value("${cloudlink.EventName}")
    private String EventName;

    @Value("${cloudlink.appType}")
    private String appType;

    @Test
    public void send(){
//        JSONObject json = new JSONObject();
//        json.put("dataModel","qwe");
//        json.put("group","测试异常信息");
//        json.put("topic","topic");
        SendModel sendModel=new SendModel();
        sendModel.setDataModel("qwe");
        sendModel.setGroup("group");
        sendModel.setTopic("asd");
        Message<SendModel> message =cloudlink.newMessageBuilder() .direct(appId,EventName, sendModel).build();
        System.out.println(message.getHeaders().getMessageId());
        cloudlink.sendMessage(message);
    }



    @Test
    public void SendMsg(){
        JSONObject json = new JSONObject();
        json.put("ip","127.0.0.1");
        json.put("message","测试异常信息");
        Event sendEvent = cloudlink.newEventBuilder().eventType(EventName)
                .eventOperation(EventOperation.Create)
                .module(appType)
                .payload(json).build();
        System.out.println(sendEvent);
        cloudlink.publishEvent(sendEvent);
    }

    public static class VO implements Serializable {
        private Object dataModel;
        private String Group;
        private String Topic;

        public Object getDataModel() {
            return dataModel;
        }

        public void setDataModel(Object dataModel) {
            this.dataModel = dataModel;
        }

        public String getGroup() {
            return Group;
        }

        public void setGroup(String group) {
            Group = group;
        }

        public String getTopic() {
            return Topic;
        }

        public void setTopic(String topic) {
            Topic = topic;
        }
    }
}
